class LoggedMappingMixin:
    """
    Add logging to get/set/delete operations for debugging
    """
    __slots__ = ()

    def __getitem__(self, key):
        print(f'Getting {key}')
        return super().__getitem__(key)

    def __setitem__(self, key, value):
        print('Setting {} = {!r}'.format(key, value))
        return super().__setitem__(key, value)

    def __delitem__(self, key):
        print('Deleting {}'.format(key))
        return super().__delitem__(key)
        pass


class SetOnceMappingMixin:
    __slots__ = ()

    def __setitem__(self, key, value):
        if key in self:
            raise KeyError(f'Key {key} already exists')
        return super().__setitem__(key, value)


class LoggedDict(LoggedMappingMixin, dict):
    pass


if __name__ == '__main__':
    logged_dict = LoggedDict()
    logged_dict['x'] = 'age'
    print(logged_dict['x'])

    print(logged_dict.__dict__)
